package com.ssy.lingxi.search.repository;

import com.ssy.lingxi.search.entity.Purchase;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;

import java.util.List;

/**
 * 进货单持久化层
 * @author jw.chen
 * @version 2.0.0
 * @date 2020/9/4
 */
public interface PurchaseRepository extends JpaRepository<Purchase,Long>, JpaSpecificationExecutor<Purchase> {
    List<Purchase> findByMemberIdAndMemberRoleIdAndShopId(Long memberId, Long memberRoleId, Long shopId);

    List<Purchase> findByMemberIdAndMemberRoleIdAndShopIdAndCustomerMemberIdAndCustomerMemberRoleId(Long memberId, Long memberRoleId, Long shopId, Long customerMemberId, Long customerMemberRoleId);

    List<Purchase> findByUserIdAndSetMealIdAndShopId(Long userId, Long setMealId, Long shopId);

    List<Purchase> findByIdIn(List<Long> idList);

    Purchase findFirstByMemberIdAndMemberRoleIdAndCommodityUnitPriceIdAndShopId(Long memberId, Long memberRoleId, Long commodityUnitPriceAndPicId, Long shopId);

    Purchase findFirstByMemberIdAndMemberRoleIdAndCommodityUnitPriceIdAndShopIdAndPurchaseCommodityType(Long memberId, Long memberRoleId, Long commodityUnitPriceAndPicId, Long shopId, Integer purchaseCommodityType);

    Purchase findFirstByMemberIdAndMemberRoleIdAndCommodityUnitPriceIdAndShopIdAndPurchaseCommodityTypeAndSetMealId(Long memberId, Long memberRoleId, Long commodityUnitPriceAndPicId, Long shopId, Integer purchaseCommodityType, Long setMealId);

    Integer countByMemberIdAndMemberRoleIdAndShopId(Long memberId, Long memberRoleId, Long shopId);

    Integer countByMemberIdAndMemberRoleIdAndShopIdAndCustomerMemberIdAndCustomerMemberRoleId(Long memberId, Long memberRoleId, Long shopId, Long customerMemberId, Long customerMemberRoleId);

    Purchase findFirstByMemberIdAndMemberRoleIdAndCommodityUnitPriceIdAndShopIdAndPurchaseCommodityTypeAndCustomerMemberIdAndCustomerMemberRoleId(Long memberId, Long memberRoleId, Long commodityUnitPriceId, Long shopId, Integer purchaseCommodityType, Long customerMemberId, Long customerMemberRoleId);

    List<Purchase> findByMemberIdAndMemberRoleIdAndShopIdAndCustomerMemberIdAndCustomerMemberRoleIdAndOrderId(Long memberId, Long memberRoleId, Long shopId, Long customerMemberId, Long customerMemberRoleId, Long orderId);

    Integer countByMemberIdAndMemberRoleIdAndShopIdAndCustomerMemberIdAndCustomerMemberRoleIdAndOrderId(Long memberId, Long memberRoleId, Long shopId, Long customerMemberId, Long customerMemberRoleId, Long orderId);

    Purchase findFirstByMemberIdAndMemberRoleIdAndCommodityUnitPriceIdAndShopIdAndPurchaseCommodityTypeAndCustomerMemberIdAndCustomerMemberRoleIdAndOrderId(Long memberId, Long memberRoleId, Long commodityUnitPriceId, Long shopId, Integer purchaseCommodityType, Long customerMemberId, Long customerMemberRoleId, Long orderId);

    Purchase findFirstByMemberIdAndMemberRoleIdAndCommodityUnitPriceIdAndShopIdAndPurchaseCommodityTypeAndSetMealIdAndCustomerMemberId(Long memberId, Long memberRoleId, Long commodityUnitPriceId, Long shopId, Integer purchaseCommodityType, Long setMealId, Long customerMemberId);

    Purchase findFirstByMemberIdAndMemberRoleIdAndCommodityUnitPriceIdAndShopIdAndPurchaseCommodityTypeAndSetMealIdAndCustomerMemberIdAndOrderId(Long memberId, Long memberRoleId, Long commodityUnitPriceId, Long shopId, Integer purchaseCommodityType, Long setMealId, Long customerMemberId, Long orderId);
}
